package de.au.fi.calc.criteria.complex;

import de.au.fi.calc.CalcHelper;
import de.au.fi.calc.criteria.Criteria;

public class CriteriaKgv5J extends Criteria {
	
	Double[] kgvs;

	public CriteriaKgv5J(Double... kgvs) {
		super("KGV 5J");
		this.kgvs = kgvs;
	}
	
	@Override
	public int calculate() {
		int nullValues = 0;
		if(kgvs == null)return 0;
		Double kgvSum = 0.0;
		for(Double kgv : kgvs)
		{
			if(kgv != null)
				kgvSum = kgvSum + kgv;
			else
				nullValues++;
		}
		if(kgvs.length <= 2)return 0;
		if(nullValues > 2)return 0;
		if(kgvSum == 0.0)return 0;
		kgvSum = kgvSum / (kgvs.length - nullValues);
		return CalcHelper.calculateKgv(kgvSum);
	}

}
